<?php

/**
 * Created by PhpStorm.
 * User: nansion
 * Date: 12/6/16
 * Time: 2:50 PM
 */
//implements SessionHandlerInterface
namespace utils\session;

class MySessionHandler implements \SessionHandlerInterface
{
    private $savePath;

    public function open($savePath, $sessionName)
    {
        $this->savePath = $savePath;
        if (!is_dir($this->savePath)) {
            mkdir($this->savePath, 0777);
        }

        return true;
    }

    public function close()
    {
        return true;
    }

    public function read($sessionName)
    {
        return (string)@file_get_contents("$this->savePath/$sessionName");
    }

    public function write($sessionName, $data)
    {
        return file_put_contents("$this->savePath/$sessionName", $data) === false ? false : true;
    }

    public function destroy($id)
    {
        return true;
    }

    public function gc($maxlifetime)
    {
        return true;
    }
}